package com.shuoyue.ycgk.ui.questionbank.reportwrong;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.views.dialog.common.HintConfirmDialog;

import butterknife.BindView;
import butterknife.OnClick;

public class ReportWrongQuestionActivity extends BaseMvpActivity<ReportWrongContract.Presenter> implements ReportWrongContract.View {


    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.wrong_text)
    CheckBox wrongText;
    @BindView(R.id.notmatch)
    CheckBox notmatch;
    @BindView(R.id.alyWrong)
    CheckBox alyWrong;
    @BindView(R.id.other)
    CheckBox other;
    @BindView(R.id.phone_num)
    EditText phoneNum;

    int type, objId;

    public static void start(Context context, int type, int objId) {
        context.startActivity(new Intent(context, ReportWrongQuestionActivity.class)
                .putExtra("type", type)
                .putExtra("objId", objId));
    }

    /**
     * 初始化layouy
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_report_wrong_question;
    }

    /**
     * 初始化布局
     */
    @Override
    protected void initView() {
        pageTitle.setText("错题反馈");
    }

    @Override
    public void initData() {
        super.initData();
        type = getIntent().getIntExtra("type", 0);
        objId = getIntent().getIntExtra("objId", 0);

        mPresenter = new ReportWrongContract.Presenter();
        mPresenter.attachView(this);
    }

    @OnClick({R.id.back, R.id.wrong_text, R.id.notmatch, R.id.alyWrong, R.id.other, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.wrong_text:
                wrongText.setChecked(true);
                notmatch.setChecked(false);
                alyWrong.setChecked(false);
                other.setChecked(false);
                break;
            case R.id.notmatch:
                notmatch.setChecked(true);
                wrongText.setChecked(false);
                alyWrong.setChecked(false);
                other.setChecked(false);
                break;
            case R.id.alyWrong:
                alyWrong.setChecked(true);
                notmatch.setChecked(false);
                wrongText.setChecked(false);
                other.setChecked(false);
                break;
            case R.id.other:
                other.setChecked(true);
                notmatch.setChecked(false);
                alyWrong.setChecked(false);
                wrongText.setChecked(false);
                break;
            case R.id.submit:
                HintConfirmDialog hintConfirmDialog = new HintConfirmDialog(mContext, "报错", "是否提交");
                hintConfirmDialog.setOkListener(v -> {
                    int subtype = 1;//// 1：错别字 ，2：答案解析不匹配， 3：解析错误，4：其他
                    if (wrongText.isChecked()) {
                        subtype = 1;
                    }
                    if (alyWrong.isChecked()) {
                        subtype = 3;
                    }
                    if (notmatch.isChecked()) {
                        subtype = 2;
                    }
                    if (other.isChecked()) {
                        subtype = 4;
                    }
                    mPresenter.feedback(type, subtype, phoneNum.getText().toString(), objId);
                    hintConfirmDialog.dismiss();
                });
                hintConfirmDialog.show();
                break;
        }
    }

    @Override
    public void reportSuc() {
        toast("已提交");
        finish();
    }
}
